package cn.com.czpb.client.module.nanning.activity;

import android.net.http.SslError;
import android.os.Build;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import cn.com.czpb.client.R;
import cn.com.czpb.client.app.MToolBarActivity;

import butterknife.BindView;

public class FuWuActivity extends MToolBarActivity {


    @BindView(R.id.webview_fuwu)
    WebView webView;
    @BindView(R.id.ll_back)
    LinearLayout ll_back;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_fu_wu;
    }

    @Override
    public void initData() {
        super.initData();
        ll_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

        final WebSettings settings=webView.getSettings();
        settings.setSavePassword(false);
        settings.setJavaScriptEnabled(true);
        settings.setSupportZoom(true);
        settings.setBuiltInZoomControls(true);

        settings.setDomStorageEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setAppCacheEnabled(true);
        webView.setWebViewClient(new WebViewClient(){
            //网站证书，接受证书
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

                handler.proceed();
                //6.0以后接收证书
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
                }
            }

        });

//        int type=getIntent().getIntExtra("type",0);
        String url = getIntent().getStringExtra("fuwuurl");
        webView.loadUrl(url);
//       switch (type){
//           case 0://美食
//               webView.loadUrl(InterfaceJsonfile.MEISHI);
//               break;
//           case 1://酒店
//               webView.loadUrl(InterfaceJsonfile.JIUDIAN);
//               break;
//           case 2://电影
//               webView.loadUrl(InterfaceJsonfile.MAOYAN);
//               break;
//           case 3://美团
//               webView.loadUrl(InterfaceJsonfile.MEITUAN);
//               break;
//           case 4://火车票
//               webView.loadUrl(InterfaceJsonfile.HUOCHEPIAO);
//               break;
//           case 5://天气
//               webView.loadUrl(InterfaceJsonfile.TIANQI);
//               break;
//           case 6://快递
//               webView.loadUrl(InterfaceJsonfile.KUAIDI);
//               break;
//       }
    }
    @Override
    // 设置回退
    // 覆盖Activity类的onKeyDown(int keyCoder,KeyEvent event)方法
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
            webView.goBack(); // goBack()表示返回WebView的上一页面
            return true;
        }
        return super.onKeyDown(keyCode,event);
    }


}
